﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EHTSaleManager.Code.Entity;
using EHTSaleManager.Code.DAL;
using System.Data.SqlClient;
using System.Data;

namespace EHTSaleManager.Code.BLL
{
    public class QuangCaoProvider
    {
        public static DataSet GetQuangCao()
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetQuangcao";
            command.CommandType = CommandType.StoredProcedure;
            return DataProvider.ExecuteDataSet(command);
        }
        public static DataSet GetDeleteQuangCao(Int32 QuangCaoID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_DeleteQuangCaos";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@QuangCaoID",QuangCaoID));
            return DataProvider.ExecuteDataSet(command);
        }
        public static DataSet GetPhanVungQuangCao(Int32 PhanVungID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_PhanVungQuangCaos";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@PhanVungID",PhanVungID));
            return DataProvider.ExecuteDataSet(command);
        }
        public static void InsertQuangCaos(Quangcao theQuangCao, bool IsAdd)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_IUQuangCaos";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@QuangCaoID",theQuangCao.QuangCaoID));
            command.Parameters.Add(new SqlParameter("@NoiDung",theQuangCao.NoiDung));
            command.Parameters.Add(new SqlParameter("@DeleteFlag",theQuangCao.DeleteFlag));
            command.Parameters.Add(new SqlParameter("@PhanVungID",theQuangCao.PhanVungID));
            command.Parameters.Add(new SqlParameter("@IsAdd",IsAdd));
            DataProvider.ExecuteNoneQuery(command);
        }

        public static Quangcao GetQuangCaosbyQuangCaosid(Int32 QuangCaoID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetQuangCaosByQuangCaosid ";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@QuangCaoID",QuangCaoID));
            DataSet ds = DataProvider.ExecuteDataSet(command);
            Quangcao theQuangCao = null;
            if (ds.Tables[0].Rows.Count > 0)
            {
                theQuangCao = new Quangcao();
                theQuangCao.QuangCaoID = Int32.Parse(ds.Tables[0].Rows[0]["QuangCaoID"].ToString());
                theQuangCao.NoiDung = ds.Tables[0].Rows[0]["NoiDung"].ToString();
                theQuangCao.DeleteFlag = Boolean.Parse(ds.Tables[0].Rows[0]["DeleteFlag"].ToString());
                theQuangCao.PhanVungID = Int32.Parse(ds.Tables[0].Rows[0]["PhanVungID"].ToString());
            }
            return theQuangCao;
        }
    }
}